<template>
	<div>
	<el-form ref="ruleForm" :rules="rules" :model="form" label-width="80px">
		<el-form-item label="标题" prop="title">
			<el-input v-model="form.title" placeholder="请输入标题"></el-input>
		</el-form-item>
		
		<el-form-item label="商品路径">
			<el-input v-model="form.url" placeholder="/pages/index/index?id=7"></el-input>
		</el-form-item>
		<el-form-item label="排序">
			<el-input v-model="form.index"></el-input>
		</el-form-item>
		<el-form-item label="">
			<el-button type="primary" @click="submitForm('ruleForm')">确 定</el-button>
		</el-form-item>
	</el-form>
	</div>
</template>

<script>
	
	export default {
		
		data() {
			return {
				form: {
					id:"",
					name: '',
					index:1,
					url:"",
				},
				rules: {
					name: [{
						required: true,
						message: '请输入名称',
						trigger: 'blur'
					},],
				

				}

			}
		},
		created() {
		  if(this.$route.query.id){
		  	   this.jiazai(this.$route.query)
		  }
		},
		methods: {
			jiazai(e){
				this.axios.post("/api/index/findNotice", {
					id: e.id
				}).then(res => {
					this.form=res;
				}).catch(error => {
				
				})
			},
			submitForm(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						this.axios.post("/admin/user/addNotice", {
							title: this.form.title,
							id:this.form.id,
							index:this.form.index,
							url:this.form.url,
							
						}).then(res => {
							this.$message.success({
								message: "添加成功",
								onClose: (res) => {
									this.$router.replace("/notice")
								}
							})
						}).catch(error => {

						})
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
		}
	}
</script>

<style>
</style>
